package com.tingyukeji.fastpay.my.activity;

import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.tingyukeji.fastpay.R;
import com.tingyukeji.fastpay.base.BaseActivity;
import com.tingyukeji.fastpay.my.adapter.BankListAdapter;
import com.tingyukeji.fastpay.databinding.BankListActivityBinding;
import com.tingyukeji.fastpay.my.fragment.CreditBankCardFragment;
import com.tingyukeji.fastpay.my.fragment.DebitBankCardFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/11.
 */

public class BankListActivity extends BaseActivity {
    private BankListActivityBinding binding;
    private FragmentManager fragmentManager;
    private DebitBankCardFragment debitBankCardFragment;
    private CreditBankCardFragment creditBankCardFragment;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setContentView() {
        super.setContentView();
        binding = DataBindingUtil.setContentView(this, R.layout.bank_list_activity);
    }

    @Override
    protected void initView() {
        super.initView();
        debitBankCardFragment = new DebitBankCardFragment();
        creditBankCardFragment = new CreditBankCardFragment();
        fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.fl_bank, debitBankCardFragment);
        transaction.add(R.id.fl_bank, creditBankCardFragment);
        hideAllFragment(transaction);
        transaction.show(debitBankCardFragment);
        if (!isDestroyed()) transaction.commitAllowingStateLoss();
        binding.icAddBank.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        binding.tvDebitBankCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                binding.tvDebitBankCard.setTextColor(Color.parseColor("#000000"));
                binding.tvDebitBankCard.setBackgroundResource(R.drawable.debit_card_select_bg);
                binding.tvCreditBankCard.setTextColor(Color.parseColor("#ffffff"));
                binding.tvCreditBankCard.setBackgroundResource(R.drawable.credit_card_unselect_bg);
                binding.icAddBank.setVisibility(View.GONE);
                binding.addDebitCar.setVisibility(View.VISIBLE);
                FragmentTransaction transaction = fragmentManager.beginTransaction();
                hideAllFragment(transaction);
                transaction.show(debitBankCardFragment);
                if (!isDestroyed()) transaction.commitAllowingStateLoss();
            }
        });
        binding.tvCreditBankCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                binding.tvDebitBankCard.setTextColor(Color.parseColor("#ffffff"));
                binding.tvDebitBankCard.setBackgroundResource(R.drawable.debit_card_unselect_bg);
                binding.tvCreditBankCard.setTextColor(Color.parseColor("#000000"));
                binding.tvCreditBankCard.setBackgroundResource(R.drawable.credit_card_select_bg);
                binding.icAddBank.setVisibility(View.VISIBLE);
                binding.addDebitCar.setVisibility(View.GONE);
                FragmentTransaction transaction = fragmentManager.beginTransaction();
                hideAllFragment(transaction);
                transaction.show(creditBankCardFragment);
                if (!isDestroyed()) transaction.commitAllowingStateLoss();
            }
        });
        binding.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        binding.icAddBank.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }

    private void hideAllFragment(FragmentTransaction transaction) {
        if (debitBankCardFragment != null)
            transaction.hide(debitBankCardFragment);
        if (creditBankCardFragment != null)
            transaction.hide(creditBankCardFragment);
    }
}
